package ArrayList

type StackArrayX interface {
	Clear()                //清空
	Size() int             //大小
	Pop() interface{}      //弹出
	Push(data interface{}) //压入
	IsFull() bool          //是否满
	IsEmpty() bool         //是否空
}

type StackX struct {
	myarray *ArrayList //自定义ArrayList
	Myit    Iterator	//迭代器
}

func NewArrayListStackX() *StackX {
	mystack := new(StackX)
	mystack.myarray = NewArrayList() //数组
	mystack.Myit = mystack.myarray.Iterator()
	return mystack
}

func (mystack *StackX) Clear() {
	mystack.myarray.Clear()
	mystack.myarray.TheSize=0
}

func (mystack *StackX) Size() int {
	return mystack.myarray.TheSize
}

func (mystack *StackX) Pop() interface{} {
	if !mystack.IsEmpty() { //如果栈不为空则可以出栈
		last := mystack.myarray.dataStore[mystack.myarray.TheSize-1]
		mystack.myarray.Delete(mystack.myarray.TheSize - 1)
		return last
	}
	return nil
}

func (mystack *StackX) Push(data interface{}) {
	if !mystack.IsFull() {
		mystack.myarray.Append(data)
	}
}

//IsFull 判断是否满了
func (mystack *StackX) IsFull() bool {
	return mystack.myarray.TheSize >= 10
}

//IsEmpty 判断是否空
func (mystack *StackX) IsEmpty() bool {
	return mystack.myarray.TheSize == 0
}
